﻿using MediatR;
using MediatR.Pipeline;
using Traceability.APP.Application.Command.Breeding;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Breeding
{
    /// <summary>
    /// 养殖信息显示
    /// </summary>
    public class ShowBreedingCommandHandle:IRequestHandler<ShowBreedingCommand,APIResult<List<Breeding_Information>>>
    {
        private readonly IBaseRepository<Breeding_Information> BreedDal;

        public ShowBreedingCommandHandle(IBaseRepository<Breeding_Information> breedDal)
        {
            BreedDal = breedDal;
        }

        public Task<APIResult<List<Breeding_Information>>> Handle(ShowBreedingCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Breeding_Information>> result = new APIResult<List<Breeding_Information>>();
            var list = BreedDal.GetAll().Where(x => x.IsDeleted == false && x.Batch == request.Batch);
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }


    }
}
